using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using SHDocVw;
using Thinxoft.HttpLib;

namespace Thinxoft.XedusLive
{
	/// <summary>
	/// Summary description for SiteBuilderForm.
	/// </summary>
	public class SiteBuilderForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnPreview;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.RichTextBox txtEditor;
		string fileName;
		private System.Windows.Forms.Button button1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		HttpApplication  application;

		public SiteBuilderForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		
		}

		public void Display(string file,string path, HttpApplication application)
		{
			this.application  = application;
			this.fileName = file;
			txtEditor.LoadFile(path,RichTextBoxStreamType.PlainText);
			this.Show();
			this.fileName = fileName;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SiteBuilderForm));
            this.btnPreview = new System.Windows.Forms.Button();
            this.panel1 = new System.Windows.Forms.Panel();
            this.button1 = new System.Windows.Forms.Button();
            this.txtEditor = new System.Windows.Forms.RichTextBox();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
// 
// btnPreview
// 
            this.btnPreview.BackgroundImage = Thinxoft.XedusLive.Properties.Resources.save;
            this.btnPreview.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.btnPreview.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.btnPreview.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnPreview.Location = new System.Drawing.Point(7, 5);
            this.btnPreview.Name = "btnPreview";
            this.btnPreview.Size = new System.Drawing.Size(169, 23);
            this.btnPreview.TabIndex = 0;
            this.btnPreview.Text = "Save and Preview";
            this.btnPreview.Click += new System.EventHandler(this.btnPreview_Click);
// 
// panel1
// 
            this.panel1.Controls.Add(this.button1);
            this.panel1.Controls.Add(this.btnPreview);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.panel1.Location = new System.Drawing.Point(0, 411);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(525, 33);
            this.panel1.TabIndex = 1;
// 
// button1
// 
            this.button1.BackgroundImage = Thinxoft.XedusLive.Properties.Resources.help;
            this.button1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.button1.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button1.Location = new System.Drawing.Point(190, 5);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(117, 24);
            this.button1.TabIndex = 1;
            this.button1.Text = "x-file help";
            this.button1.Click += new System.EventHandler(this.button1_Click);
// 
// txtEditor
// 
            this.txtEditor.Dock = System.Windows.Forms.DockStyle.Fill;
            this.txtEditor.Location = new System.Drawing.Point(0, 0);
            this.txtEditor.Name = "txtEditor";
            this.txtEditor.Size = new System.Drawing.Size(525, 411);
            this.txtEditor.TabIndex = 2;
            this.txtEditor.Text = "";
// 
// SiteBuilderForm
// 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(525, 444);
            this.Controls.Add(this.txtEditor);
            this.Controls.Add(this.panel1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "SiteBuilderForm";
            this.Text = "Site Builder";
            this.Closing += new System.ComponentModel.CancelEventHandler(this.DoClose);
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);

        }
		#endregion

		private void btnPreview_Click(object sender, System.EventArgs e)
		{
			txtEditor.SaveFile(this.fileName,RichTextBoxStreamType.PlainText);
			System.Diagnostics.Process.Start("http://localhost:4274/" + fileName);			
		}

		private void DoClose(object sender, System.ComponentModel.CancelEventArgs e)
		{
			e.Cancel = true;
			this.Hide();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			int port = 4274;
			System.Diagnostics.Process.Start("iexplore","http://localhost:" + port + "/x-intro.htm");
		}
	}
}
